<?php
    // +----------------------------------------------------------------------
    // | 海豚PHP框架 [ DolphinPHP ]
    // +----------------------------------------------------------------------
    // | 版权所有 2016~2017 河源市卓锐科技有限公司 [ http://www.zrthink.com ]
    // +----------------------------------------------------------------------
    // | 官方网站: http://dolphinphp.com
    // +----------------------------------------------------------------------
    // | 开源协议 ( http://www.apache.org/licenses/LICENSE-2.0 )
    // +----------------------------------------------------------------------

    namespace app\cms\home;

    use app\store\model\WalletProductModel;
    use think\Db;

    /**
     * 前台首页控制器
     *
     * @package app\cms\admin
     */
    class Index extends Common
    {

        public function getNews()
        {

            $map    = [
                'status' => 1,
                'id'     => 1
            ];
            $column = Db::name('cms_column')->where($map)->find();
            $model  = Db::name('cms_model')->where('id',$column['model'])->find();

            $cid_all   = \app\cms\model\Column::getChildsId(1);
            $cid_all[] = (int)1;

            $map = [
                $model['table'] . '.trash'  => 0,
                $model['table'] . '.status' => 1,
                $model['table'] . '.cid'    => ['in',$cid_all]
            ];

            return Db::view($model['table'],true)->view('admin_user','username',$model['table'] . '.uid=admin_user.id','left')->where($map)->order('create_time desc')->limit(4)->select();

        }

        public function initialize()
        {

            parent::initialize(); // TODO: Change the autogenerated stub

            $this->assign('goods_list',WalletProductModel::lists('',4)); //获取商品

            $this->assign('news',$this->getNews()); //获取商品

//            dump($this->getNews());
//            dump(Db::getLastSql());


        }

        /**
         * 首页
         *
         * @author 蔡伟明 <314013107@qq.com>
         * @return mixed
         */
        public function index()
        {

            return $this->fetch(); // 渲染模板
        }
    }